/**
 * 
 */
package de.cbf.cam.dsa.tavern.carte.model.generators;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.operation.IRunnableWithProgress;

import de.cbf.cam.dsa.tavern.carte.model.ModelCarte;
import de.cbf.cam.dsa.tavern.carte.model.entities.Ingredient;
import de.cbf.cam.dsa.tavern.carte.model.entities.helper.MinMax;

/**
 * @author Stefan Alter
 *
 */
public abstract class AbstractMealGenerator implements IRunnableWithProgress{	
	protected ModelCarte model;
	protected HashMap<String,MinMax> configMap ;
	
	protected IProgressMonitor monitorProgress;
	private List<Ingredient> ingredients = new ArrayList<Ingredient>();
	
	
	public AbstractMealGenerator() {		
	}

	protected abstract List<Ingredient> collectMealIngredients();

	public List<Ingredient> getMealIngredients(){
		if(configMap != null && model !=null){
			return collectMealIngredients();
		}
		return new ArrayList<Ingredient>();
	}
	
	
	public HashMap<String, MinMax> getConfigMap() {
		return configMap;
	}

	public void setConfigMap(HashMap<String, MinMax> configMap) {
		this.configMap = configMap;
	}

	public ModelCarte getModel() {
		return model;
	}

	public void setModel(ModelCarte model) {
		this.model = model;
	}
	
	/**
	 * @return the ingredients
	 */
	public List<Ingredient> getIngredients() {		
		return ingredients;
	}
	
	@Override
	public void run(IProgressMonitor monitor) throws InvocationTargetException,
			InterruptedException {
		monitorProgress = monitor;
		monitorProgress.beginTask("Suche Zutaten...",IProgressMonitor.UNKNOWN);
		ingredients = collectMealIngredients();
		monitorProgress.done();
	}
	
	
	
}
